<?php

namespace app\modules\borrowers\models\search;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\modules\borrowers\models\Borrower;

/**
 * BorrowerSearch represents the model behind the search form about `app\modules\borrowers\models\Borrower`.
 */
class BorrowerSearch extends Borrower
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['borrowerID', 'isDeleted', 'borrowMonth', 'auditMonth', 'payedMonth', 'isDelayed', 'delayedAmt', 'delayedMonthAmt', 'isBorrowerRedeem', 'IsGuarantee', 'IsPawn', 'GroupId'], 'integer'],
            [['userName', 'englishName', 'nickName', 'custSeqNo', 'email', 'phone', 'birthday', 'tel', 'fax', 'webSite', 'province', 'city', 'county', 'billAddress', 'billPostCode', 'customerStatus', 'intention', 'accountStatus', 'accountDate', 'identityNo', 'education', 'gender', 'duty', 'companyName', 'customerMantainUser', 'customerAuth', 'comments', 'signContractDate', 'contractNo', 'createTime', 'createUser', 'updateTime', 'updateUser', 'owner', 'borrowerFrom', 'customerLevel', 'customerType', 'paymentDay', 'borrowerSeqNo', 'transferedUser', 'transferedDate', 'delayedNextPaymentDay', 'homeAddress', 'nextMonth', 'delayedMonth', 'job', 'borrowPurpose', 'signContractAddress', 'fangkuanBankName', 'fangkuanBankCode', 'borrowerCustomerType', 'pactAddress', 'identityAddress', 'fangkuanTime', 'aheadPaymentDate', 'riskStatus', 'jieqingTime', 'userName2ND', 'phone2ND', 'identityNo2ND', 'caiwukoukuanDate', 'team', 'Souce'], 'safe'],
            [['incomes', 'borrowAmt', 'auditAmt', 'contractAmt', 'paymentAmtByMonth', 'windAmt', 'tapeAmt', 'fengxianjin', 'tiqianhuankuanAmt', 'Grade'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Borrower::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'borrowerID' => $this->borrowerID,
            'birthday' => $this->birthday,
            'accountDate' => $this->accountDate,
            'isDeleted' => $this->isDeleted,
            'signContractDate' => $this->signContractDate,
            'createTime' => $this->createTime,
            'updateTime' => $this->updateTime,
            'incomes' => $this->incomes,
            'borrowAmt' => $this->borrowAmt,
            'borrowMonth' => $this->borrowMonth,
            'paymentDay' => $this->paymentDay,
            'auditAmt' => $this->auditAmt,
            'auditMonth' => $this->auditMonth,
            'transferedDate' => $this->transferedDate,
            'contractAmt' => $this->contractAmt,
            'payedMonth' => $this->payedMonth,
            'isDelayed' => $this->isDelayed,
            'paymentAmtByMonth' => $this->paymentAmtByMonth,
            'delayedNextPaymentDay' => $this->delayedNextPaymentDay,
            'nextMonth' => $this->nextMonth,
            'delayedMonth' => $this->delayedMonth,
            'delayedAmt' => $this->delayedAmt,
            'delayedMonthAmt' => $this->delayedMonthAmt,
            'windAmt' => $this->windAmt,
            'fangkuanTime' => $this->fangkuanTime,
            'aheadPaymentDate' => $this->aheadPaymentDate,
            'isBorrowerRedeem' => $this->isBorrowerRedeem,
            'tapeAmt' => $this->tapeAmt,
            'fengxianjin' => $this->fengxianjin,
            'jieqingTime' => $this->jieqingTime,
            'tiqianhuankuanAmt' => $this->tiqianhuankuanAmt,
            'caiwukoukuanDate' => $this->caiwukoukuanDate,
            'IsGuarantee' => $this->IsGuarantee,
            'IsPawn' => $this->IsPawn,
            'Grade' => $this->Grade,
            'GroupId' => $this->GroupId,
        ]);

        $query->andFilterWhere(['like', 'userName', $this->userName])
            ->andFilterWhere(['like', 'englishName', $this->englishName])
            ->andFilterWhere(['like', 'nickName', $this->nickName])
            ->andFilterWhere(['like', 'custSeqNo', $this->custSeqNo])
            ->andFilterWhere(['like', 'email', $this->email])
            ->andFilterWhere(['like', 'phone', $this->phone])
            ->andFilterWhere(['like', 'tel', $this->tel])
            ->andFilterWhere(['like', 'fax', $this->fax])
            ->andFilterWhere(['like', 'webSite', $this->webSite])
            ->andFilterWhere(['like', 'province', $this->province])
            ->andFilterWhere(['like', 'city', $this->city])
            ->andFilterWhere(['like', 'county', $this->county])
            ->andFilterWhere(['like', 'billAddress', $this->billAddress])
            ->andFilterWhere(['like', 'billPostCode', $this->billPostCode])
            ->andFilterWhere(['like', 'customerStatus', $this->customerStatus])
            ->andFilterWhere(['like', 'intention', $this->intention])
            ->andFilterWhere(['like', 'accountStatus', $this->accountStatus])
            ->andFilterWhere(['like', 'identityNo', $this->identityNo])
            ->andFilterWhere(['like', 'education', $this->education])
            ->andFilterWhere(['like', 'gender', $this->gender])
            ->andFilterWhere(['like', 'duty', $this->duty])
            ->andFilterWhere(['like', 'companyName', $this->companyName])
            ->andFilterWhere(['like', 'customerMantainUser', $this->customerMantainUser])
            ->andFilterWhere(['like', 'customerAuth', $this->customerAuth])
            ->andFilterWhere(['like', 'comments', $this->comments])
            ->andFilterWhere(['like', 'contractNo', $this->contractNo])
            ->andFilterWhere(['like', 'createUser', $this->createUser])
            ->andFilterWhere(['like', 'updateUser', $this->updateUser])
            ->andFilterWhere(['like', 'owner', $this->owner])
            ->andFilterWhere(['like', 'borrowerFrom', $this->borrowerFrom])
            ->andFilterWhere(['like', 'customerLevel', $this->customerLevel])
            ->andFilterWhere(['like', 'customerType', $this->customerType])
            ->andFilterWhere(['like', 'borrowerSeqNo', $this->borrowerSeqNo])
            ->andFilterWhere(['like', 'transferedUser', $this->transferedUser])
            ->andFilterWhere(['like', 'homeAddress', $this->homeAddress])
            ->andFilterWhere(['like', 'job', $this->job])
            ->andFilterWhere(['like', 'borrowPurpose', $this->borrowPurpose])
            ->andFilterWhere(['like', 'signContractAddress', $this->signContractAddress])
            ->andFilterWhere(['like', 'fangkuanBankName', $this->fangkuanBankName])
            ->andFilterWhere(['like', 'fangkuanBankCode', $this->fangkuanBankCode])
            ->andFilterWhere(['like', 'borrowerCustomerType', $this->borrowerCustomerType])
            ->andFilterWhere(['like', 'pactAddress', $this->pactAddress])
            ->andFilterWhere(['like', 'identityAddress', $this->identityAddress])
            ->andFilterWhere(['like', 'riskStatus', $this->riskStatus])
            ->andFilterWhere(['like', 'userName2ND', $this->userName2ND])
            ->andFilterWhere(['like', 'phone2ND', $this->phone2ND])
            ->andFilterWhere(['like', 'identityNo2ND', $this->identityNo2ND])
            ->andFilterWhere(['like', 'team', $this->team])
            ->andFilterWhere(['like', 'Souce', $this->Souce]);

        return $dataProvider;
    }
}
